﻿using System;
using System.Runtime.InteropServices;

namespace Terraria.Utilities
{
	// Token: 0x020000CA RID: 202
	public static class FileOperationAPIWrapper
	{
		// Token: 0x06000AC6 RID: 2758
		[DllImport("shell32.dll", CharSet = CharSet.Auto)]
		private static extern int SHFileOperation(ref FileOperationAPIWrapper.SHFILEOPSTRUCT FileOp);

		// Token: 0x06000AC7 RID: 2759 RVA: 0x003E724C File Offset: 0x003E544C
		private static bool Send(string path, FileOperationAPIWrapper.FileOperationFlags flags)
		{
			bool result;
			try
			{
				FileOperationAPIWrapper.SHFILEOPSTRUCT shfileopstruct = new FileOperationAPIWrapper.SHFILEOPSTRUCT
				{
					wFunc = FileOperationAPIWrapper.FileOperationType.FO_DELETE,
					pFrom = path + "\0\0",
					fFlags = (FileOperationAPIWrapper.FileOperationFlags.FOF_ALLOWUNDO | flags)
				};
				FileOperationAPIWrapper.SHFileOperation(ref shfileopstruct);
				result = true;
			}
			catch (Exception)
			{
				result = false;
			}
			return result;
		}

		// Token: 0x06000AC8 RID: 2760 RVA: 0x0000B82E File Offset: 0x00009A2E
		private static bool Send(string path)
		{
			return FileOperationAPIWrapper.Send(path, FileOperationAPIWrapper.FileOperationFlags.FOF_NOCONFIRMATION | FileOperationAPIWrapper.FileOperationFlags.FOF_WANTNUKEWARNING);
		}

		// Token: 0x06000AC9 RID: 2761 RVA: 0x0000B83B File Offset: 0x00009A3B
		public static bool MoveToRecycleBin(string path)
		{
			return FileOperationAPIWrapper.Send(path, FileOperationAPIWrapper.FileOperationFlags.FOF_SILENT | FileOperationAPIWrapper.FileOperationFlags.FOF_NOCONFIRMATION | FileOperationAPIWrapper.FileOperationFlags.FOF_NOERRORUI);
		}

		// Token: 0x06000ACA RID: 2762 RVA: 0x003E72AC File Offset: 0x003E54AC
		private static bool DeleteFile(string path, FileOperationAPIWrapper.FileOperationFlags flags)
		{
			bool result;
			try
			{
				FileOperationAPIWrapper.SHFILEOPSTRUCT shfileopstruct = new FileOperationAPIWrapper.SHFILEOPSTRUCT
				{
					wFunc = FileOperationAPIWrapper.FileOperationType.FO_DELETE,
					pFrom = path + "\0\0",
					fFlags = flags
				};
				FileOperationAPIWrapper.SHFileOperation(ref shfileopstruct);
				result = true;
			}
			catch (Exception)
			{
				result = false;
			}
			return result;
		}

		// Token: 0x06000ACB RID: 2763 RVA: 0x0000B848 File Offset: 0x00009A48
		private static bool DeleteCompletelySilent(string path)
		{
			return FileOperationAPIWrapper.DeleteFile(path, FileOperationAPIWrapper.FileOperationFlags.FOF_SILENT | FileOperationAPIWrapper.FileOperationFlags.FOF_NOCONFIRMATION | FileOperationAPIWrapper.FileOperationFlags.FOF_NOERRORUI);
		}

		// Token: 0x020000CB RID: 203
		[Flags]
		private enum FileOperationFlags : ushort
		{
			// Token: 0x04000F21 RID: 3873
			FOF_SILENT = 4,
			// Token: 0x04000F22 RID: 3874
			FOF_NOCONFIRMATION = 16,
			// Token: 0x04000F23 RID: 3875
			FOF_ALLOWUNDO = 64,
			// Token: 0x04000F24 RID: 3876
			FOF_SIMPLEPROGRESS = 256,
			// Token: 0x04000F25 RID: 3877
			FOF_NOERRORUI = 1024,
			// Token: 0x04000F26 RID: 3878
			FOF_WANTNUKEWARNING = 16384
		}

		// Token: 0x020000CC RID: 204
		private enum FileOperationType : uint
		{
			// Token: 0x04000F28 RID: 3880
			FO_MOVE = 1u,
			// Token: 0x04000F29 RID: 3881
			FO_COPY,
			// Token: 0x04000F2A RID: 3882
			FO_DELETE,
			// Token: 0x04000F2B RID: 3883
			FO_RENAME
		}

		// Token: 0x020000CD RID: 205
		[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto, Pack = 1)]
		private struct SHFILEOPSTRUCT
		{
			// Token: 0x04000F2C RID: 3884
			public IntPtr hwnd;

			// Token: 0x04000F2D RID: 3885
			[MarshalAs(UnmanagedType.U4)]
			public FileOperationAPIWrapper.FileOperationType wFunc;

			// Token: 0x04000F2E RID: 3886
			public string pFrom;

			// Token: 0x04000F2F RID: 3887
			public string pTo;

			// Token: 0x04000F30 RID: 3888
			public FileOperationAPIWrapper.FileOperationFlags fFlags;

			// Token: 0x04000F31 RID: 3889
			[MarshalAs(UnmanagedType.Bool)]
			public bool fAnyOperationsAborted;

			// Token: 0x04000F32 RID: 3890
			public IntPtr hNameMappings;

			// Token: 0x04000F33 RID: 3891
			public string lpszProgressTitle;
		}
	}
}
